package com.akhan.jplearn.service.impl;

import cn.hutool.core.lang.Console;

import java.util.Scanner;

/**
 * 基础服务接口
 *
 * @author YuKang
 * @date 2021/6/25 0:07
 * @return
 */
public abstract class BaseServiceImpl {
    /**
     *  输出欢迎标语
     *
     * @author YuKang
     * @date 2021/6/25 0:08
     */
    void hello(){

    }

    void back(){

    }

    public void run(){
        Console.log("开始{}", getName());
        while (true) {
            Console.log(prepare());
            Scanner scanner = new Scanner(System.in);
            String input = scanner.next();
            if ("back".equals(input)){
                back();
            }else if ("exit".equals(input)){
                System.exit(0);
            }else {
                String ret = core(input);
                if (ret == null) {
                    ret = "输入有误, 请重试";
                }
                Console.log(ret);
            }
        }
    }

    abstract String core(String in);

    String prepare(){
        return "";
    }

    /**
     * 服务名
     *
     * @author YuKang
     * @date 2021/6/25 0:16
     * @return String 服务名
     */
    abstract String getName();
}
